package com.yellow.cloud.system.controller;

import com.yellow.cloud.system.service.SysLogService;
import com.yellowframework.cloud.api.system.SysLogControllerApi;
import com.yellowframework.cloud.common.annotation.FeignLogin;
import com.yellowframework.cloud.common.model.response.ObjectResponseResult;
import com.yellowframework.cloud.common.model.response.QueryResponseResult;
import com.yellowframework.cloud.common.model.response.ResponseResult;
import com.yellowframework.cloud.domain.system.SysDetailLog;
import com.yellowframework.cloud.domain.system.SysOperateLog;
import com.yellowframework.cloud.domain.system.request.QuerySysLogRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/log")
public class SysLogController implements SysLogControllerApi {

    @Autowired
    private SysLogService sysLogService;

    @Override
    @PreAuthorize("hasAuthority('sys:log:list')")
    @GetMapping(value = "/page/list/{page}/{size}")
    public QueryResponseResult<SysOperateLog> pageList(@PathVariable("page") Integer page, @PathVariable("size") Integer size, QuerySysLogRequest request) {
        return sysLogService.pageList(page, size, request);
    }

    @Override
    @PreAuthorize("hasAuthority('sys:log:details')")
    @GetMapping(value = "/details/{type}/{id}")
    public ObjectResponseResult<String> details(@PathVariable("type") Integer type, @PathVariable("id") Integer id) {
        return sysLogService.details(type, id);
    }

    @FeignLogin(client = false)
    @PostMapping("operatelog")
    public ResponseResult saveOperatelog(@RequestBody SysOperateLog request) {
        sysLogService.saveOperatelog(request);
        return ResponseResult.success();
    }

    @FeignLogin(client = false)
    @PostMapping("detaillog")
    public ResponseResult saveDetaillog(@RequestBody SysDetailLog request) {
        sysLogService.saveDetailLog(request);
        return ResponseResult.success();
    }

}
